$('.article').livequery(function() {
	$('.edit-link, .comment-link').on('click', function(){
		$(this.parentNode).hide();
		$('.comm-text').show();
		return false;
	});
	
	var working = false;
	$('form.answer').on('submit', function() {
		var text = $('textarea', this).val();
		if(text == '') alert('Укажите текст');
		else if(text.length > 2000) alert('Текст - не более 2000 символов');
		else if(working) return false;
		else {
			working = true;
			$.ajax({
				dataType: 'json',
				url: W_AJAX + 'article/comment',
				type: 'POST',
				data: {
					text: $('#ArticleComment_text').val(),
					ID_article: $('#ArticleComment_ID_article').val()
				},
				success: function(data) {
					if(data.result == 'OK') {
						$('#ArticleComment_text').val('');
						$('.comm-text').slideUp();
						$('.to-hide').show();
						if(!$('.comments p').length) $('.comments').append('<p>Вопросы и комментарии</p>');
						$('.comments').append(data.block);
					}
					working = false;
				}	
			});
		}
		return false;
	});
	
	$('body').click(function(event){
		var block = $(event.target).closest('.comm-text');
		if(!block.length) {
			$('.comm-text').hide();
			$('.to-hide').show();
		}
	});
});